package com.zjhn.ds.common;

/**
 * 自定义返回类别
 *
 * @param <T>
 */
public class BizResult<T> {

    /**
     * 返回code
     */
    private String code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回的数据
     */
    private T Data;

    /**
     * success
     * @return
     */
    public static BizResult<?> success(){
        return new BizResult<>(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMsg());
    }

    /**
     * success 带参数
     * @param data
     * @return
     */
    public static<T> BizResult<T> success(T data){
        return new BizResult<>(ResultEnum.SUCCESS, data);
    }

    /**
     * fail
     * @param resultEnum
     * @return
     * @param <T>
     */
    public static<T> BizResult<T> fail(ResultEnum resultEnum){
        return new BizResult<>(resultEnum.getCode(), resultEnum.getMsg());
    }

    /**
     * fail
     * @param message
     * @return
     */
    public static<T> BizResult<T> fail(String message){
        return new BizResult<>(ResultEnum.FAILED.getCode(), message);
    }

    public BizResult(ResultEnum resultEnum, T data) {
        this.code = resultEnum.getCode();
        this.message = resultEnum.getMsg();
        Data = data;
    }

    public BizResult(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public BizResult(String code, String message, T data) {
        this.code = code;
        this.message = message;
        Data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return Data;
    }

    public void setData(T data) {
        Data = data;
    }
}
